package cn.edu.hbpu.controller.v1;

import cn.edu.hbpu.common.R;
import cn.edu.hbpu.dto.UserDto;
import cn.edu.hbpu.entity.User;
import cn.edu.hbpu.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;


/**
 * @author lcy
 * @date 2022/8/4 11:56
 * @description
 */

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 生成验证码
     *
     * @return
     */
    @GetMapping("/code")
    public R<Map<Object, Object>> code() throws IOException {
        return userService.generateCode();
    }

    /**
     * 用户登录
     *
     * @param user
     * @return
     */
    @PostMapping("/login")
    public R<Map<Object, Object>> login(@RequestBody UserDto user) {
        return userService.login(user);
    }

    /**
     * 注册用户
     *
     * @param user
     * @return
     */
    @PostMapping("/register")
    public R<Map<Object, Object>> register(@RequestBody UserDto user) {
        return userService.register(user);
    }

    /**
     * 退出登录
     * @return
     */
    @GetMapping("/logout")
    public R<Map<Object, Object>> logout() {
        return userService.logout();
    }

    /**
     * 获取用户个人信息
     * @return
     */
    @GetMapping("/profile")
    public R<User> getUserInfo() {
        return userService.getUserInfo();
    }
}
